﻿Imports MeoTom.Core.BLL
Imports Microsoft.ApplicationBlocks.Data

Namespace DAL
    Public Class TagProvider
        Inherits DataAccess

        Private util As New Utilities.Common()

        Public Sub New()

        End Sub

        Public Sub Create(ByVal t As Tags)
            Try
                Dim param(3) As SqlClient.SqlParameter
                param(0) = New SqlClient.SqlParameter("@ArticleID", SqlDbType.Int, 4)
                param(0).Value = t.ArticleID
                param(1) = New SqlClient.SqlParameter("@TagName", SqlDbType.NVarChar, 50)
                param(1).Value = util.NoHTML(t.TagName)
                param(2) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
                param(2).Value = Configs.SiteID

                SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Tag_Create", param)
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Sub

        Public Function Update(ByVal t As Tags) As SqlClient.SqlDataReader
            Dim param(3) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@TagName", SqlDbType.NVarChar, 50)
            param(0).Value = t.TagName
            param(1) = New SqlClient.SqlParameter("@TagID", SqlDbType.Int, 4)
            param(1).Value = t.TagID
            param(2) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(2).Value = Configs.SiteID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_Tags_UpdateTagName", param)
        End Function

        Public Sub Delete(ByVal t As Tags)
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@TagID", SqlDbType.Int, 4)
            param(0).Value = t.TagID
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Tags_Delete", param)
        End Sub

        Public Function GetByID(ByVal t As Tags) As SqlClient.SqlDataReader
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@TagID", SqlDbType.Int, 4)
            param(0).Value = t.TagID
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_Tags_GetByID", param)
        End Function

        Public Function GetTagByArticleEdit(ByVal t As Tags) As SqlClient.SqlDataReader
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@ArticleID", SqlDbType.Int, 4)
            param(0).Value = t.ArticleID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_Tags_GetByArticle", param)
        End Function

        Public Function GetAllTags() As SqlClient.SqlDataReader
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(0).Value = Configs.SiteID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_TagsGetAll", param)
        End Function

        Public Function GetArticleByTag(ByVal t As Tags) As DataSet
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@TagID", SqlDbType.Int, 4)
            param(0).Value = t.TagID
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            Return SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "Justin_Article_GetByTag", param)
        End Function

        Public Function GetAll() As DataSet
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(0).Value = Configs.SiteID

            Return SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "Justin_TagsGetAll", param)
        End Function

        Public Function GetTagData() As DataSet
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(0).Value = Configs.SiteID

            Return SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "Justin_Tags_GetAll", param)
        End Function

        Public Function GetTagByArticle(ByVal t As Tags) As SqlClient.SqlDataReader
            Dim param(0) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@ArticleID", SqlDbType.Int, 4)
            param(0).Value = t.ArticleID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_Tags_GetByArticleID", param)
        End Function

        Public Sub UpdateTotalArticle(ByVal t As Tags)
            Try
                Dim param(1) As SqlClient.SqlParameter
                param(0) = New SqlClient.SqlParameter("@TagID", SqlDbType.Int, 4)
                param(0).Value = t.TagID
                param(1) = New SqlClient.SqlParameter("@TotalTag", SqlDbType.Int, 4)
                param(1).Value = t.TotalTag

                SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Tags_UpdateTotalArticle", param)
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Sub
    End Class
End Namespace
